package 序列化和反序列化;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class 序列化 {
    public static void main(String[] args) {


        try (
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("prt\\src\\oops.txt"));
        ) {
            // 写单个
            user us = new user("张三", 23);
            objectOutputStream.writeObject(us);

            // 写多个
            user us1 = new user("李四",24);
            user us2 = new user("王五",26);
            List<user> list = new ArrayList<>();
            Collections.addAll(list,us1,us2);
            objectOutputStream.writeObject(list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
